<template>
  <div class="login">
    <div>
      <van-form label-align="center">
        <van-field
          v-model="loginForm.username"
          name="账号"
          label="账号"
          placeholder="test"
          :rules="[{ required: true, message: '请填写账号test' }]"
        />
        <van-field
          v-model="loginForm.password"
          type="password"
          name="密码"
          label="密码"
          placeholder="123456"
          :rules="[{ required: true, message: '请填写密码123456' }]"
        />
        <div style="margin: 16px">
          <van-button
            round
            block
            type="info"
            native-type="submit"
            @click="register()"
            >注册</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>
<script>
import { mapMutations, mapGetters } from "vuex";

export default {
  data() {
    return {
      loginForm: {
        username: "",
        password: "",
      },
    };
  },
  computed: {
    ...mapMutations("user", ["setUser"]),
    ...mapGetters("user", ["isLogin"]),
  },
  methods: {
    register() {
      this.$store.commit("user/register", [
        this.loginForm.username,
        this.loginForm.password,
      ]);
      this.$toast.success("注册成功");

      this.$router.replace({ name: "login" });
    },
  },
};
</script>
